<%-- 
    Document   : newEvent
    Created on : 18-gen-2015, 16.51.41
    Author     : Jov
--%>
<%@page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@page import="java.sql.*"%>
<%@page import="java.io.*"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <meta http-equiv="refresh" content="0; url=../index.jsp">
        <title>JSP Page</title>
    </head>
    <body>
        <h1>I-I-I'm here to create a new event, p-p-please be gentle, s-senpai-san!</h1>
        <%
            out.println("The year recognized is: " + request.getParameter("year"));
            out.println("The month recognized is: " + request.getParameter("month"));
            out.println("The day recognized is: " + request.getParameter("day"));
            out.println("The location recognized is: " + request.getParameter("location"));
            out.println("The begin hour recognized is: " + request.getParameter("hour"));
            out.println("The begin minute recognized is: " + request.getParameter("minute"));
            out.println("The duration recognized is: " + request.getParameter("duration"));
            out.println("The name of the event is: " + request.getParameter("name"));
        %>

        <%
            try {
                String connectionURL = "jdbc:mysql://localhost:3306/meteocaldb";
                Connection connection = null;
                Class.forName("com.mysql.jdbc.Driver").newInstance();
                connection = DriverManager.getConnection(connectionURL, "root", "0000");

                Statement stmt = connection.createStatement();
                
                stmt.executeUpdate("INSERT INTO events VALUES (NULL,'"+request.getParameter("name")+"',"+request.getParameter("year")+","+request.getParameter("month")+","+request.getParameter("day")+","+request.getParameter("hour")+","+request.getParameter("minute")+","+request.getParameter("duration")+",'"+request.getParameter("location")+"',"+request.getParameter("privacy")+","+request.getParameter("shared")+","+session.getAttribute("user_id")+",'"+request.getParameter("desiredWeather")+"','',0,0,0,0)");

                stmt.close();
                connection.close();

            } catch (Exception ex) {
                out.println("Errore! " + ex.getMessage().toString());
            }
        %>  
    </body>
</html>
